<?php
/*********************************************************************************
 * Copyright (C) 2011-2013 X2Engine Inc. All Rights Reserved.
 *
 * X2Engine Inc.
 * P.O. Box 66752
 * Scotts Valley, California 95067 USA
 *
 * Company website: http://www.x2engine.com
 * Community and support website: http://www.x2community.com
 *
 * X2Engine Inc. grants you a perpetual, non-exclusive, non-transferable license
 * to install and use this Software for your internal business purposes.
 * You shall not modify, distribute, license or sublicense the Software.
 * Title, ownership, and all intellectual property rights in the Software belong
 * exclusively to X2Engine.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT.
 ********************************************************************************/

/* @edition:pro */

?>
<div class="page-title">
	<h2><?php echo Yii::t('admin','Edit Role Access'); ?></h2>
	<a href="#" class="x2-button btn btn-mini  btn-yellow left" onclick='$("#role-info").slideToggle();'><?php echo Yii::t('admin','Show Info'); ?></a>
</div>
<div class="form" id="role-info" style="display:none;">
<div id="role-info" class="form" style="width:600px;">
  <p><?php echo Yii::t('admin','To edit access permissions on roles, select a role from the dropdown list below.');?></p>
  <p><?php echo Yii::t('admin','The "Default Role" is assigned to all users upon login, but <u>does not apply</u> to the admin user.  All roles inherit permissions lower than them. Furthermore, permissions assume the most permissive setting, so if Default Role has "Update Access" to Contacts, and your role only gives "Basic Access," the user will still have "Update Access"');?><br><br>
    <?php echo Yii::t('admin','Here is a brief description of each access level, in order of increasing permissions.');?><br>
  </p>
  <table width="100%" border="1" cellspacing="0" cellpadding="5">
    <tr>
      <th width="175" bgcolor="#CCCCCC" scope="row"><?php echo Yii::t('admin','(empty)');?></th>
      <td><p><?php echo Yii::t('admin',"A single dash represents no access changes.  The role will use the permissions from the 'Default Role' to determine access.");?></p>
      <p><?php echo Yii::t('admin',"If the 'Default Role' has a dash, then users will not be able to access it.");?></p></td>
    </tr>
    <tr>
      <th width="175" bgcolor="#CCCCCC" scope="row"><?php echo Yii::t('admin','Read Only Access');?></th>
      <td><?php echo Yii::t('admin','Users with this role will be able to see that the module exists and view all records that they have access to (determined by visibility rules).');?></td>
    </tr>
    <tr>
      <th width="175" bgcolor="#CCCCCC" scope="row"><?php echo Yii::t('admin','Basic Access');?></th>
      <td><?php echo Yii::t('admin',"Users with this role will  inherit 'Read Only Access' permissions and are additionally able to create records.");?></td>
    </tr>
    <tr>
      <th width="175" bgcolor="#CCCCCC" scope="row"><?php echo Yii::t('admin','Update Access');?></th>
      <td><?php echo Yii::t('admin',"Users with this role will  inherit 'Basic Access' permissions and are additionally able to update all records they are allowed to access.");?></td>
    </tr>
    <tr>
      <th width="175" bgcolor="#CCCCCC" scope="row"><?php echo Yii::t('admin','Full Access');?></th>
      <td><?php echo Yii::t('admin',"Users with this role will  inherit 'Update Access' permissions and are additionally able to delete records they are allowed to access.");?></td>
    </tr>
    <tr>
      <th width="175" bgcolor="#CCCCCC" scope="row"><?php echo Yii::t('admin','Admin Access');?></th>
      <td><?php echo Yii::t('admin',"Users with this role will  inherit 'Full Access' permissions and have unrestricted access to the module, including functions like import/export if they exist on that module.");?></td>
    </tr>
  </table>
  <p><?php echo Yii::t('admin',"There are also a few 'Private' flavor access levels that mirror the above except users will only be able to see records explicity assigned to them. These are listed below.");?></p>
  <table width="100%" border="1" cellspacing="0" cellpadding="5">
    <tr>
      <th width="175" bgcolor="#CCCCCC" scope="row"><?php echo Yii::t('admin','Private Read Only Access');?></th>
      <td><span class="form" style="width:600px;"><?php echo Yii::t('admin',"Works the same as 'Read Only Access' except users will only be able to see records explicitly assigned to them.");?></span></td>
    </tr>
    <tr>
      <th width="175" bgcolor="#CCCCCC" scope="row"><?php echo Yii::t('admin','Private Update Access');?></th>
      <td><?php echo Yii::t('admin',"Works the same as 'Update Access' except users will only be able to update records explicitly assigned to them.");?></td>
    </tr>
    <tr>
      <th width="175" bgcolor="#CCCCCC" scope="row"><?php echo Yii::t('admin','Private Full Access');?></th>
      <td><?php echo Yii::t('admin',"Works the same as 'Full Access' except users will only be able to delete records explicitly assigned to them.");?></td>
    </tr>
  </table>
  <p><?php echo Yii::t('admin','If you flag a role as <b>admin</b>, that role will have full access to all modules as well as the administrator tab, superceding any other permissions.');?><br>
  </p>
</div>
</div>
<div class="form">
<?php
Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl().'/js/multiselect/js/ui.multiselect.js');
Yii::app()->clientScript->registerCssFile(Yii::app()->getBaseUrl().'/js/multiselect/css/ui.multiselect.css','screen, projection');
Yii::app()->clientScript->registerCss('multiselectCss',"
.multiselect {
	width: 460px;
	height: 200px;
}
#switcher {
	margin-top: 20px;
}
",'screen, projection');
$list=Roles::model()->findAll();
$names=array('DefaultRole'=>'Default Role');
foreach($list as $role){
    $names[$role->name]=$role->name;
}
?>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'roleEdit-form',
	'enableAjaxValidation'=>false,
        'action'=>'editRoleAccess',
)); ?>

	<em><?php echo Yii::t('app','Fields with <span class="required">*</span> are required.'); ?></em><br>

        <div class="row">
            <?php echo $form->labelEx($model,'name'); ?>
            <?php echo $form->dropDownList($model,'name',$names,array(
                'empty'=>Yii::t('admin','Select a role'),
                'id'=>'editDropdown',
                'ajax' => array(
                'type'=>'POST', //request type
                'url'=>CController::createUrl('admin/getRoleAccess'), //url to call.
                //Style: CController::createUrl('currentController/methodToCall')
                'update'=>'#role-access-form', //selector to update
                'complete'=>"function(){
                    $('.multiselect').multiselect();
                    var dropdownValue=$('#editDropdown').val();
                    if(dropdownValue!='authenticated' && dropdownValue!='')
                        $('#admin-flag-box').show();
                    else
                        $('#admin-flag-box').hide();
                    if(dropdownValue=='')
                        $('#roleForm').hide();
                    else
                        $('#roleForm').show();
                }"
                //'data'=>'js:"modelType="+$("'.CHtml::activeId($model,'modelType').'").val()'
                //leave out the data key to pass all form values through
                ))); ?>
            <?php echo $form->error($model,'name'); ?>
        </div>

        <div id="roleForm">
            <div class="row" id="admin-flag-box" style="display:none;">
                <?php echo CHtml::label(Yii::t('admin','Flag as Admin?'), 'adminFlag'); ?>
                <?php echo CHtml::checkBox('adminFlag',false,array(
                    'id'=>'admin-flag',
                    'onclick'=>'toggleRoleForm();',

                )); ?>
            </div>
            <div id="role-access-form">

            </div>
        </div>
        <br>
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('app','Save'):Yii::t('app','Save'),array('class'=>'x2-button btn btn-mini  btn-yellow')); ?>
	</div>
<?php $this->endWidget(); ?>
</div>
<script>
function toggleRoleForm(){
    var value=$('#admin-flag').attr('checked');
    if(value=='checked'){
        $('#role-access-form').hide();
    }else{
        $('#role-access-form').show();
    }

}
</script>